/*
 * @Descripttion:主入口文件
 * @version:
 * @Author: yangzhihao
 * @Date: 2021-07-09 15:33:02
 * @LastEditors: yangzhihao
 * @LastEditTime: 2021-07-14 15:02:02
 */
import { AxiosInstance } from './constant/index'
import Axios from './core/Axios'
import { extend } from './utils'
// 创建axios实例
function createInstance(): AxiosInstance {
  const context = new Axios()
  // 这一步是因为最后导出的axios也能当函数用，对应Axios类的request方法，因为其它接口要用到this，所以将this绑定为实例
  const instance = Axios.prototype.request.bind(context)

  extend(instance, context)

  return instance as AxiosInstance
}

const axios = createInstance()
export default axios
